home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / rastan.c < prev    next >
C/C++ Source or Header  |  2000-05-19  |  7KB  |  311 lines

  1. #include "driver.h"
  2. #include "cpu/z80/z80.h"
  3.  
  4.  
  5. /**********************************************************************************************
  6.     Soundboard Status bitfield definition:
  7.      bit meaning
  8.       0  Set if theres any data pending that the main cpu sent to the slave
  9.       1  ??? ( Its not being checked both on Rastan and SSI
  10.       2  Set if theres any data pending that the slave sent to the main cpu
  11.  
  12. ***********************************************************************************************
  13.  
  14.     It seems like 1 nibble commands are only for control purposes.
  15.     2 nibble commands are the real messages passed from one board to the other.
  16.  
  17. **********************************************************************************************/
  18.  
  19. /* Some logging defines */
  20. #if 0
  21. #define REPORT_SLAVE_MODE_CHANGE
  22. #define REPORT_SLAVE_MODE_READ_ITSELF
  23. #define REPORT_MAIN_MODE_READ_SLAVE
  24. #define REPORT_DATA_FLOW
  25. #endif
  26.  
  27. static int nmi_enabled=0; /* interrupts off */
  28.  
  29. /* status of soundboard ( reports any commands pending ) */
  30. static unsigned char SlaveContrStat = 0;
  31.  
  32. static int transmit=0; /* number of bytes to transmit/receive */
  33. static int tr_mode;    /* transmit mode (1 or 2 bytes) */
  34. static int lasthalf=0; /* in 2 bytes mode this is first nibble (LSB bits 0,1,2,3) received */
  35.  
  36. static int m_transmit=0; /* as above but for motherboard*/
  37. static int m_tr_mode;    /* as above */
  38. static int m_lasthalf=0; /* as above */
  39.  
  40. static int IRQ_req=0; /*no request*/
  41. static int NMI_req=0; /*no request*/
  42.  
  43. static unsigned char soundcommand;
  44. static unsigned char soundboarddata;
  45.  
  46. /***********************************************************************/
  47. /*  looking from sound board point of view ...                         */
  48. /***********************************************************************/
  49.  
  50. WRITE_HANDLER( rastan_c000_w )
  51. /* Meaning of this address is unknown !!! */
  52. {
  53. }
  54.  
  55. WRITE_HANDLER( rastan_d000_w )
  56. /* ADPCM chip used in Rastan does not stop playing the sample by itself
  57. ** it must be said to stop instead. This is the address that does it.
  58. */
  59. {
  60.     if (Machine->samples == 0) return;
  61. #if 0
  62.     if (data==0)
  63.         mixer_stop_sample(channel);
  64. #endif
  65. }
  66.  
  67. void Interrupt_Controller(void)
  68. {
  69.     if (IRQ_req) {
  70.         cpu_cause_interrupt(1,0);
  71.         /* IRQ_req = 0; */
  72.     }
  73.  
  74.     if ( NMI_req && nmi_enabled ) {
  75.         cpu_cause_interrupt( 1, Z80_NMI_INT );
  76.         NMI_req = 0;
  77.     }
  78. }
  79.  
  80. READ_HANDLER( rastan_a001_r )
  81. {
  82.  
  83.     static unsigned char pom=0;
  84.  
  85.     if (transmit == 0)
  86.     {
  87.         logerror("Slave unexpected receiving! (PC = %04x)\n", cpu_get_pc() );
  88.     }
  89.     else
  90.     {
  91.         if (tr_mode == 1)
  92.         {
  93.             pom = SlaveContrStat;
  94. #ifdef REPORT_SLAVE_MODE_READ_ITSELF
  95.             logerror("Slave has read status of itself %02x (PC = %04x)\n",pom, cpu_get_pc() );
  96. #endif
  97.         }
  98.         else
  99.         {            /*2-bytes transmision*/
  100.             if (transmit==2)
  101.             {
  102.                 pom = soundcommand & 0x0f;
  103. #ifdef REPORT_DATA_FLOW
  104.                 logerror("Slave has read pom1=%02x (PC = %04x)\n",pom, cpu_get_pc() );
  105. #endif
  106.             }
  107.             else
  108.             {
  109.                 pom = (soundcommand & 0xf0) >> 4;
  110. #ifdef REPORT_DATA_FLOW
  111.                 logerror("Slave has read pom2=%02x (PC = %04x)\n",pom,cpu_get_pc() );
  112. #endif
  113.                 SlaveContrStat &= 0xfe; /* Ready to receive new commands */;
  114.             }
  115.         }
  116.         transmit--;
  117.     }
  118.  
  119.     Interrupt_Controller();
  120.  
  121.     return pom;
  122. }
  123.  
  124. WRITE_HANDLER( rastan_a000_w )
  125. {
  126.     int pom;
  127.  
  128.     if (transmit != 0)
  129.         logerror("Slave mode changed while expecting to transmit! (PC = %04x) \n", cpu_get_pc() );
  130.  
  131. #ifdef REPORT_SLAVE_MODE_CHANGE
  132.     logerror("Slave changing its mode to %02x (PC = %04x) \n",data, cpu_get_pc());
  133. #endif
  134.  
  135.     pom = (data >> 2 ) & 0x01;
  136.     transmit = 1 + (1 - pom); /* one or two bytes long transmission */
  137.     lasthalf = 0;
  138.     tr_mode = transmit;
  139.  
  140.     pom = data & 0x03;
  141.     if (pom == 0x01)
  142.         nmi_enabled = 0; /* off */
  143.  
  144.     if (pom == 0x02)
  145.     {
  146.         nmi_enabled = 1; /* on */
  147.     }
  148.  
  149.     if (pom == 0x03)
  150.         logerror("Int mode = 3! (PC = %04x)\n", cpu_get_pc() );
  151. }
  152.  
  153. WRITE_HANDLER( rastan_a001_w )
  154. {
  155.     data &= 0x0f;
  156.  
  157.     if (transmit == 0)
  158.     {
  159.         logerror("Slave unexpected transmission! (PC = %04x)\n", cpu_get_pc() );
  160.     }
  161.     else
  162.     {
  163.         if (transmit == 2)
  164.             lasthalf = data;
  165.         transmit--;
  166.         if (transmit==0)
  167.         {
  168.             if (tr_mode == 2)
  169.             {
  170.                 soundboarddata = lasthalf + (data << 4);
  171.                 SlaveContrStat |= 4; /* report data pending on main */
  172.                 cpu_spin(); /* writing should take longer than emulated, so spin */
  173. #ifdef REPORT_DATA_FLOW
  174.                 logerror("Slave sent double %02x (PC = %04x)\n",lasthalf+(data<<4), cpu_get_pc() );
  175. #endif
  176.             }
  177.             else
  178.             {
  179. #ifdef REPORT_DATA_FLOW
  180.                 logerror("Slave issued control value %02x (PC = %04x)\n",data, cpu_get_pc() );
  181. #endif
  182.             }
  183.         }
  184.     }
  185.  
  186.     Interrupt_Controller();
  187. }
  188.  
  189. WRITE_HANDLER( rastan_adpcm_trigger_w )
  190. {
  191.     ADPCM_trigger(0,data);
  192. }
  193.  
  194. void rastan_irq_handler (int irq)
  195. {
  196.     IRQ_req = irq;
  197. }
  198.  
  199. /***********************************************************************/
  200. /*  now looking from main board point of view                          */
  201. /***********************************************************************/
  202.  
  203. WRITE_HANDLER( rastan_sound_port_w )
  204. {
  205.     int pom;
  206.  
  207.     if ((data&0xff) != 0x01)
  208.     {
  209.         pom = (data >> 2 ) & 0x01;
  210.         m_transmit = 1 + (1 - pom); /* one or two bytes long transmission */
  211.         m_lasthalf = 0;
  212.         m_tr_mode = m_transmit;
  213.     }
  214.     else
  215.     {
  216.         if (m_transmit == 1)
  217.         {
  218.             /*logerror("single-doubled (first was=%02x)\n",m_lasthalf);*/
  219.         }
  220.         else
  221.         {
  222.             logerror("rastan_sound_port_w() - unknown innerworking\n");
  223.         }
  224.     }
  225. }
  226.  
  227. WRITE_HANDLER( rastan_sound_comm_w )
  228. {
  229.     data &= 0x0f;
  230.  
  231.     if (m_transmit == 0)
  232.     {
  233.         logerror("Main unexpected transmission! (PC = %08x)\n", cpu_get_pc() );
  234.     }
  235.     else
  236.     {
  237.         if (m_transmit == 2)
  238.             m_lasthalf = data;
  239.  
  240.         m_transmit--;
  241.  
  242.         if (m_transmit==0)
  243.         {
  244.             if (m_tr_mode == 2)
  245.             {
  246.                 soundcommand = m_lasthalf + (data << 4);
  247.                 SlaveContrStat |= 1; /* report data pending for slave */
  248.                 NMI_req = 1;
  249. #ifdef REPORT_DATA_FLOW
  250.                 logerror("Main sent double %02x (PC = %08x) \n",m_lasthalf+(data<<4), cpu_get_pc() );
  251. #endif
  252.             }
  253.             else
  254.             {
  255. #ifdef REPORT_DATA_FLOW
  256.                 logerror("Main issued control value %02x (PC = %08x) \n",data, cpu_get_pc() );
  257. #endif
  258.                 /* this does a hi-lo transition to reset the sound cpu */
  259.                 if (data)
  260.                     cpu_set_reset_line(1,ASSERT_LINE);
  261.                 else
  262.                     cpu_set_reset_line(1,CLEAR_LINE);
  263.  
  264.                 m_transmit++;
  265.             }
  266.         }
  267.     }
  268. }
  269.  
  270. READ_HANDLER( rastan_sound_comm_r )
  271. {
  272.  
  273.     m_transmit--;
  274.     if (m_tr_mode==2)
  275.     {
  276. #ifdef REPORT_DATA_FLOW
  277.         logerror("Main read double %02x (PC = %08x)\n",soundboarddata, cpu_get_pc() );
  278. #endif
  279.         SlaveContrStat &= 0xfb; /* clear pending data for main bit */
  280.  
  281.         if ( m_transmit == 1 )
  282.             return soundboarddata & 0x0f;
  283.  
  284.         return ( soundboarddata >> 4 ) & 0x0f;
  285.  
  286.     }
  287.     else
  288.     {
  289. #ifdef REPORT_MAIN_MODE_READ_SLAVE
  290.         logerror("Main read status of Slave %02x (PC = %08x)\n",SlaveContrStat, cpu_get_pc() );
  291. #endif
  292.         m_transmit++;
  293.         return SlaveContrStat;
  294.     }
  295. }
  296.  
  297. WRITE_HANDLER( rastan_sound_w )
  298. {
  299.     if (offset == 0)
  300.         rastan_sound_port_w(0,data & 0xff);
  301.     else if (offset == 2)
  302.         rastan_sound_comm_w(0,data & 0xff);
  303. }
  304.  
  305. READ_HANDLER( rastan_sound_r )
  306. {
  307.     if (offset == 2)
  308.         return rastan_sound_comm_r(0);
  309.     else return 0;
  310. }
  311.